tyNamespace.NumLayer = cc.Layer.extend({
    num: 30,
    numWidth: 20,
    zeroImageNum: 0,
    length: 0,
    numString: "",
    pathHead:"sz_cdd_js_",
    showWanYi:false,
    //第四个参数最好不写，因为如果传3，可能会出现“000”的情况
    ctor: function (num, numWidth, zeroImageNum, pathHead, length, showWanYi) {
        this.setNum(num);
        this.numWidth = numWidth;
        
        if (pathHead)
        	this.pathHead = pathHead;
        
        this.zeroImageNum = zeroImageNum;
        if (length && length > this.length)
        	this.length = length;
        
        if (showWanYi)
        	this.showWanYi = showWanYi;

        this._super();
        this.init();
    },

    setPathHead:function(pathHead){
    	this.pathHead = pathHead;
    	this.reloadNum(this.num);
    },

    setNum: function (num) {
        this.num = num;
    	this.numString = num.toString();

        if (this.length < this.numString.length)
            this.length = this.numString.length;
    },

    init: function () {
        this._super();

        var size = cc.winSize;
        var startPosition = (this.length - 1) * this.numWidth / 2;

        if (this.showWanYi) {//显示万亿
        	var showType = 0;
        	if (this.num >= 1000000000) {
        		showType = 2;
        		this.num = parseInt(this.num / 100000000);
        	}
        	else if (this.num >= 100000) {
        		showType = 1;
        		this.num = parseInt(this.num / 10000);
        	}
        	
        	if (showType > 0) {
        		this.setNum(this.num);
        		this.length = this.numString.length;
        		startPosition = (this.length) * this.numWidth / 2;//中文 万/亿 长度

        		var imageName = this.getImageName(9 + showType);
        		
        		var numNode = new cc.Sprite(imageName);
        		numNode.attr({
        			x: this.length * this.numWidth - startPosition,
        			y: 0
        		});

        		this.addChild(numNode, 1, "numNode" + this.length);
        	}
        }

        for (var i = this.numString.length; i < this.length; i++) {
            this.numString = "0" + this.numString;
        }

        for (var i = 0; i < this.length; i++) {
            var currentChar = this.numString.charAt(i);

            var num = parseInt(currentChar);

            var imageName = this.getImageName(num);

            var numNode = new cc.Sprite(imageName);
            numNode.attr({
                x: i * this.numWidth - startPosition,
                y: 0
            });

//			cc.log("startPosition" + (i * this.numWidth - startPosition));

            this.addChild(numNode, 1, "numNode" + i);
        }
    },
    
    numFadeOut:function(delay) {
    	if (!delay) {
    		delay = 1;
    	}
    	for (var i = 0; i < this.length; i++) {
    		var numNode = this.getChildByName("numNode" + i);
    		numNode.runAction(new cc.FadeOut(delay));
    	}
    },

    getImageName: function (num) {
        var showNum = num + this.zeroImageNum;
//		cc.log("num:" + num + ",showNum:" + showNum);

        var showNumString = "";
        if (showNum < 100)
            showNumString += "0";

        if (showNum < 10)
            showNumString += "0";

        showNumString += showNum;

        //cc.log("#ddz_sz_0" + showNumString + "u.png");

        return "#" + this.pathHead + showNumString + "u.png";
    },

    reloadNum: function (num) {
        this.removeAllChildren(true);
        this.length = num.toString().length;
        this.setNum(num);
        this.init();
    }
});